<template>
  <div>
    <van-picker
      title="性别"
      show-toolbar
      :columns="columns"
      :default-index="value"
      @confirm="onConfirm"
      @cancel="$emit('close-popup')"
    />
  </div>
</template>

<script>
import { updatetUserProfile } from '@/api/user.js'
export default {
  data () {
    return {
      columns: ['男', '女']
    }
  },
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  created () {

  },

  methods: {
    async onConfirm (value, index) {
      this.$toast.loading({
        message: '保存中...',
        forbidClick: true,
        duration: 0
      })
      try {
        await updatetUserProfile({
          gender: index
        })
        this.$emit('close-popup')
        this.$emit('input', index)
        this.$toast.success('更新成功!')
      } catch (err) {
        this.$toast('更新失败!')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
